﻿namespace YidanSoft.Library.EditorUtility.Menus
{
    using System;
    using System.Drawing;

    internal class DrawCommand
    {
        protected bool _chevron;
        protected int _col;
        protected YidanSoft.Library.EditorUtility.Menus.MenuCommand _command;
        protected Rectangle _drawRect;
        protected bool _enabled;
        protected bool _expansion;
        protected char _mnemonic;
        protected int _row;
        protected bool _separator;
        protected bool _subMenu;
        protected bool _vertSeparator;

        public DrawCommand(Rectangle drawRect)
        {
            this._row = -1;
            this._col = -1;
            this._mnemonic = '0';
            this._enabled = true;
            this._subMenu = false;
            this._expansion = false;
            this._separator = false;
            this._vertSeparator = false;
            this._chevron = true;
            this._drawRect = drawRect;
            this._command = null;
        }

        public DrawCommand(Rectangle drawRect, bool expansion)
        {
            this._row = -1;
            this._col = -1;
            this._mnemonic = '0';
            this._enabled = true;
            this._subMenu = false;
            this._expansion = expansion;
            this._separator = !expansion;
            this._vertSeparator = !expansion;
            this._chevron = false;
            this._drawRect = drawRect;
            this._command = null;
        }

        public DrawCommand(YidanSoft.Library.EditorUtility.Menus.MenuCommand command, Rectangle drawRect)
        {
            this.InternalConstruct(command, drawRect, -1, -1);
        }

        public DrawCommand(YidanSoft.Library.EditorUtility.Menus.MenuCommand command, Rectangle drawRect, int row, int col)
        {
            this.InternalConstruct(command, drawRect, row, col);
        }

        public void InternalConstruct(YidanSoft.Library.EditorUtility.Menus.MenuCommand command, Rectangle drawRect, int row, int col)
        {
            this._row = row;
            this._col = col;
            this._enabled = command.Enabled;
            this._expansion = false;
            this._vertSeparator = false;
            this._drawRect = drawRect;
            this._command = command;
            this._chevron = false;
            this._separator = this._command.Text == "-";
            this._subMenu = this._command.MenuCommands.Count > 0;
            int index = command.Text.IndexOf('&');
            if ((index != -1) && (index < (command.Text.Length - 1)))
            {
                this._mnemonic = char.ToUpper(command.Text[index + 1]);
            }
        }

        public bool Chevron
        {
            get
            {
                return this._chevron;
            }
        }

        public int Col
        {
            get
            {
                return this._col;
            }
        }

        public Rectangle DrawRect
        {
            get
            {
                return this._drawRect;
            }
            set
            {
                this._drawRect = value;
            }
        }

        public bool Enabled
        {
            get
            {
                return this._enabled;
            }
        }

        public bool Expansion
        {
            get
            {
                return this._expansion;
            }
        }

        public YidanSoft.Library.EditorUtility.Menus.MenuCommand MenuCommand
        {
            get
            {
                return this._command;
            }
        }

        public char Mnemonic
        {
            get
            {
                return this._mnemonic;
            }
        }

        public int Row
        {
            get
            {
                return this._row;
            }
        }

        public bool Separator
        {
            get
            {
                return this._separator;
            }
        }

        public bool SubMenu
        {
            get
            {
                return this._subMenu;
            }
        }

        public bool VerticalSeparator
        {
            get
            {
                return this._vertSeparator;
            }
        }
    }
}

